
#ifndef PLAYER_LEVELUP_GIFT_SCRIPT_H
#define PLAYER_LEVELUP_GIFT_SCRIPT_H

#include "ScriptMgr.h"
#include "Common.h"
#include "PlayerGift.h"
#include "XpRate.h"
#include "Guild.h"
#include "Channel.h"

#define KKK_MODULE_ENABLE_KEY "KkkGiftModule.Enable"
#define KKK_MODULE_CHAT_LOG_PATH_KEY "KKKGiftModule.chat.logfile"
#define SKILL_LINE_ENCHANTING 333  //附魔技能

#define KKK_MODULE_CHAT_LOG_PREFIX "chatlog_"


class PlayerLevelUpGiftScript : public PlayerScript, public WorldScript
{
private:
    PlayerGiftCenter playerGiftCenter;
    XpRate xpRate;
   // int reloadIsRequired;
   // std::mutex initLock;
   void logChat(std::string sender /* not null */,std::string recver /* not null; player name,guild name etc */, std::string msg /* not null*/);
   bool shouldLog(std::string msg);
public:
    PlayerLevelUpGiftScript();
    void OnStartup() override;
   
    void OnPlayerLevelChanged(Player* player, uint8 oldlevel) override;

    void OnPlayerUpdateCraftingSkill(Player* player, SkillLineAbilityEntry const* skill, uint32 current_level, uint32& gain) override; //制造类生活技能

    void OnPlayerGiveXP(Player* /*player*/, uint32& /*amount*/, Unit* /*victim*/, uint8 /*xpSource*/) override; //xp rate gift

    void init();

    void setXpRate(uint64 setterGuid /*nullable*/,uint64 targetGuid /* not null*/, uint32 rate /*percentage value*/, uint32 hours, bool enabled)
    {
        xpRate.setXpRate(setterGuid,targetGuid,rate,hours,enabled);
    }

    bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 lang, std::string& msg) override{
        this->logChat(player->GetName(),"大喊",msg);
        return true;
    }
    bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver)override{
        this->logChat(player->GetName(),receiver->GetName(),msg);
        return true;
    }

    bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) override{
        this->logChat(player->GetName(),"G",msg);
        return true;
    }

    bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild) override{
        this->logChat(player->GetName(), guild->GetName(),msg);
        return true;
    }

    bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) override{
        this->logChat(player->GetName(),channel->GetName(),msg);
        return true;
    }

    //void setReloadRequiredFlag();

    //void cleanReloadRequiredFlag();

    vector<LevelUpGift*> getGifts();
     vector<LevelUpGift*> getAlleEchantingGift(){ return playerGiftCenter.getAlleEchantingGift();}
   
};

#endif

